import CustomToastComponent from './CustomToast.vue';

const CustomToast = {};
CustomToast.installed = false;

// 类似于 window.alert() 提示组件要求像调用 JS 函数一样调用它  Vue.extend + $mount

CustomToast.install = Vue => {
  Vue.prototype.$customToast = {};
  Vue.prototype.$customToast.show = (title, content) => {
    // 组件构造器(Vue.extend)
    const CustomToastConstructor = Vue.extend(CustomToastComponent);
    // 再组件实例化
    const tpl = new CustomToastConstructor();
    // console.log('tpl===', tpl);
    tpl.title = title; // 传参数
    tpl.content = content; // 传参数
    // const vm = tpl.$mount();
    // console.log(vm);
    const dom = tpl.$mount().$el; // 创建实例，在文档之外渲染成
    document.body.appendChild(dom); // 把创建的实例添加到body中
    setTimeout(() => {
      document.body.removeChild(dom); // 延迟1.5秒后移除该提示
    }, 1500);
  };
};
export default CustomToast;
